/*!
 * \file iconv2utf8.c
 *
 * All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.\n
 *
 * \version 3.0
 * \author geyh
 * \date 2016/03/31
 *
 */
#include <CUnit/Basic.h>
#include <stdlib.h>

#include "frcomm.h"
#include "frmem.h"
#include "frstr.h"
#include "iconv2utf8.h"
#include "conntrack.h"
#include "frct_comm.h"

#include "apmtest_comm.h"

static int __suite_init(void)
{

    return 0;
}

static int __suite_cleanup(void)
{

    return 0;
}


static void __case1(void)
{
    char *p_inbuffer = NULL;
    unsigned int ui_inbuffer_size = 0;
    char *p_from_charset = (char *)"UTF-8";
    char *p_output_buffer = NULL;
    unsigned int p_ui_output_size = 0;

    if(iconv_to_utf8(p_inbuffer, ui_inbuffer_size, p_from_charset, &p_output_buffer, &p_ui_output_size))
    {
        frfree(p_inbuffer);
        printf("iconv error");
        return;
    }

    CU_ASSERT_PTR_NULL(p_output_buffer);
}

static void __case2(void)
{
    char *p_inbuffer = '\0';
    unsigned int ui_inbuffer_size = 0;
    char *p_from_charset = (char *)"UTF-8";
    char *p_output_buffer = NULL;
    unsigned int p_ui_output_size = 0;

    if(iconv_to_utf8(p_inbuffer, ui_inbuffer_size, p_from_charset, &p_output_buffer, &p_ui_output_size))
    {
        frfree(p_inbuffer);
        printf("iconv error");
        return;
    }

    CU_ASSERT_PTR_NULL(p_output_buffer);
}


static void __case3(void)
{
    FILE *fp_stdin = NULL;
    FILE *fp_stdout = NULL;
    char *p_out = NULL;//实际应该输出的字符串
    int i_out_len = 0;
    char *p_inbuffer = NULL;
    unsigned int ui_inbuffer_size = 0;
    char *p_from_charset = (char *)"UTF-8";
    char *p_output_buffer = NULL;
    unsigned int p_ui_output_size = 0;

    fp_stdin = fopen("t_iconv2utf8/input1.txt","r");
    if(fp_stdin == NULL)
        return;

    fseek(fp_stdin,0,SEEK_SET);
    fseek(fp_stdin,0,SEEK_END);
    ui_inbuffer_size = ftell(fp_stdin);
    rewind(fp_stdin);

    p_inbuffer = (char *)frmalloc(ui_inbuffer_size + 1);
    if(p_inbuffer == NULL)
    {
        fclose(fp_stdin);
        return;
    }

    if(fread(p_inbuffer, 1, (int)ui_inbuffer_size,fp_stdin) != ui_inbuffer_size)
    {
        fclose(fp_stdin);
        frfree(p_inbuffer);
        return;
    }


    if(iconv_to_utf8(p_inbuffer, ui_inbuffer_size, p_from_charset, &p_output_buffer, &p_ui_output_size))
    {
        frfree(p_inbuffer);
        fclose(fp_stdin);
        printf("iconv error");
        return;
    }
    fp_stdout = fopen("t_iconv2utf8/output.txt","r");
    if(fp_stdout == NULL)
    {
        frfree(p_inbuffer);
        fclose(fp_stdin);
        frfree(p_output_buffer);
        return;
    }

    fseek(fp_stdout,0,SEEK_SET);
    fseek(fp_stdout,0,SEEK_END);
    i_out_len = ftell(fp_stdout);
    rewind(fp_stdout);

    p_out =(char *)frmalloc(i_out_len + 1);
    memset(p_out,'\0',i_out_len + 1);
    if(p_out == NULL)
    {
        frfree(p_inbuffer);
        fclose(fp_stdin);
        frfree(p_output_buffer);
        fclose(fp_stdout);
        return;
    }


    if(fread(p_out,1,i_out_len,fp_stdout) != (unsigned int)i_out_len)
    {
        frfree(p_inbuffer);
        fclose(fp_stdin);
        frfree(p_output_buffer);
        fclose(fp_stdout);
        frfree(p_out);
        return;
    }
    fclose(fp_stdout);

    CU_ASSERT_STRING_EQUAL(p_out,p_output_buffer);
    frfree(p_out);
    frfree(p_output_buffer);
    frfree(p_inbuffer);
}


static void __case4(void)
{
    FILE *fp_stdin = NULL;
    FILE *fp_stdout = NULL;
    char *p_out = NULL;//实际应该输出的字符串
    int i_out_len = 0;
    char *p_inbuffer = NULL;
    unsigned int ui_inbuffer_size = 0;
    char *p_from_charset = (char *)"GB2312";
    char *p_output_buffer = NULL;
    unsigned int p_ui_output_size = 0;

    fp_stdin = fopen("t_iconv2utf8/input2.txt","r");
    if(fp_stdin == NULL)
        return;

    fseek(fp_stdin,0,SEEK_SET);
    fseek(fp_stdin,0,SEEK_END);
    ui_inbuffer_size = ftell(fp_stdin);
    rewind(fp_stdin);

    p_inbuffer = (char *)frmalloc(ui_inbuffer_size + 1);
    if(p_inbuffer == NULL)
    {
        fclose(fp_stdin);
        return;
    }

    if(fread(p_inbuffer, 1, (int)ui_inbuffer_size,fp_stdin) != ui_inbuffer_size)
    {
        fclose(fp_stdin);
        frfree(p_inbuffer);
        return;
    }


    if(iconv_to_utf8(p_inbuffer, ui_inbuffer_size, p_from_charset, &p_output_buffer, &p_ui_output_size))
    {

        frfree(p_inbuffer);
        fclose(fp_stdin);
        printf("iconv error");

    }

    fp_stdout = fopen("t_iconv2utf8/GB2312.txt","r");
    if(fp_stdout == NULL)
    {
        frfree(p_inbuffer);
        fclose(fp_stdin);
        frfree(p_output_buffer);
        return;
    }

    fseek(fp_stdout,0,SEEK_SET);
    fseek(fp_stdout,0,SEEK_END);
    i_out_len = ftell(fp_stdout);
    rewind(fp_stdout);

    p_out =(char *)frmalloc(i_out_len + 1);
    memset(p_out,'\0',i_out_len + 1);
    if(p_out == NULL)
    {
        frfree(p_inbuffer);
        fclose(fp_stdin);
        frfree(p_output_buffer);
        fclose(fp_stdout);
        return;
    }

    memset(p_out,'\0',i_out_len + 1);

    if(fread(p_out,1,i_out_len,fp_stdout) != (unsigned int)i_out_len)
    {
        frfree(p_inbuffer);
        fclose(fp_stdin);
        frfree(p_output_buffer);
        fclose(fp_stdout);
        frfree(p_out);
        return;
    }
    fclose(fp_stdout);

    CU_ASSERT_STRING_EQUAL(p_out,p_output_buffer);
    frfree(p_out);
    frfree(p_output_buffer);
}

static void __case5(void)
{
    FILE *fp_stdin = NULL;
    FILE *fp_stdout = NULL;
    char *p_out = NULL;//实际应该输出的字符串
    int i_out_len = 0;
    char *p_inbuffer = NULL;
    unsigned int ui_inbuffer_size = 0;
    char *p_from_charset = (char *)"ISO-8859-1";
    char *p_output_buffer = NULL;
    unsigned int p_ui_output_size = 0;

    fp_stdin = fopen("t_iconv2utf8/input3.txt","r");
    if(fp_stdin == NULL)
        return;

    fseek(fp_stdin,0,SEEK_SET);
    fseek(fp_stdin,0,SEEK_END);
    ui_inbuffer_size = ftell(fp_stdin);
    rewind(fp_stdin);

    p_inbuffer = (char *)frmalloc(ui_inbuffer_size + 1);
    if(p_inbuffer == NULL)
    {
        fclose(fp_stdin);
        return;
    }

    if(fread(p_inbuffer, 1, (int)ui_inbuffer_size,fp_stdin) != ui_inbuffer_size)
    {
        fclose(fp_stdin);
        frfree(p_inbuffer);
        return;
    }


    if(iconv_to_utf8(p_inbuffer, ui_inbuffer_size, p_from_charset, &p_output_buffer, &p_ui_output_size))
    {
        frfree(p_inbuffer);
        fclose(fp_stdin);
        printf("iconv error");
    }

    fp_stdout = fopen("t_iconv2utf8/ISO-8859-1.txt","r");
    if(fp_stdout == NULL)
    {
        frfree(p_inbuffer);
        fclose(fp_stdin);
        frfree(p_output_buffer);
        return;
    }


    fseek(fp_stdout,0,SEEK_SET);
    fseek(fp_stdout,0,SEEK_END);
    i_out_len = ftell(fp_stdout);
    rewind(fp_stdout);

    p_out =(char *)frmalloc(i_out_len + 1);
    memset(p_out,'\0',i_out_len + 1);
    if(p_out == NULL)
    {
        frfree(p_inbuffer);
        fclose(fp_stdin);
        frfree(p_output_buffer);
        fclose(fp_stdout);
        return;
    }

    if(fread(p_out,1,i_out_len,fp_stdout) != (unsigned int)i_out_len)
    {
        frfree(p_inbuffer);
        fclose(fp_stdin);
        frfree(p_output_buffer);
        fclose(fp_stdout);
        frfree(p_out);
        return;
    }
    fclose(fp_stdout);


    CU_ASSERT_STRING_EQUAL(p_out,p_output_buffer);
    frfree(p_out);
    frfree(p_output_buffer);
    frfree(p_inbuffer);
}

static void __case6(void)
{
    FILE *fp_stdin = NULL;
    FILE *fp_stdout = NULL;
    char *p_out = NULL;//实际应该输出的字符串
    int i_out_len = 0;
    char *p_inbuffer = NULL;
    unsigned int ui_inbuffer_size = 0;
    char *p_from_charset = (char *)"UTF-16";
    char *p_output_buffer = NULL;
    unsigned int p_ui_output_size = 0;

    fp_stdin = fopen("t_iconv2utf8/input4.txt","r");
    if(fp_stdin == NULL)
        return;

    fseek(fp_stdin,0,SEEK_SET);
    fseek(fp_stdin,0,SEEK_END);
    ui_inbuffer_size = ftell(fp_stdin);
    rewind(fp_stdin);

    p_inbuffer = (char *)frmalloc(ui_inbuffer_size + 1);
    if(p_inbuffer == NULL)
    {
        fclose(fp_stdin);
        return;
    }

    if(fread(p_inbuffer, 1, (int)ui_inbuffer_size,fp_stdin) != ui_inbuffer_size)
    {
        fclose(fp_stdin);
        frfree(p_inbuffer);
        return;
    }


    if(iconv_to_utf8(p_inbuffer, ui_inbuffer_size, p_from_charset, &p_output_buffer, &p_ui_output_size))
    {
        frfree(p_inbuffer);
        fclose(fp_stdin);
        printf("iconv error");
    }
    fp_stdout = fopen("t_iconv2utf8/UTF-16.txt","r");
    if(fp_stdout == NULL)
    {
        frfree(p_inbuffer);
        fclose(fp_stdin);
        frfree(p_output_buffer);
        return;
    }


    fseek(fp_stdout,0,SEEK_SET);
    fseek(fp_stdout,0,SEEK_END);
    i_out_len = ftell(fp_stdout);
    rewind(fp_stdout);

    p_out =(char *)frmalloc(i_out_len + 1);
    memset(p_out,'\0',i_out_len + 1);
    if(p_out == NULL)
    {
        frfree(p_inbuffer);
        fclose(fp_stdin);
        frfree(p_output_buffer);
        fclose(fp_stdout);
        return;
    }

    if(fread(p_out,1,i_out_len,fp_stdout) != (unsigned int)i_out_len)
    {
        frfree(p_inbuffer);
        fclose(fp_stdin);
        frfree(p_output_buffer);
        fclose(fp_stdout);
        frfree(p_out);
        return;
    }
    fclose(fp_stdout);


    CU_ASSERT_STRING_EQUAL(p_out,p_output_buffer);
    frfree(p_out);
    frfree(p_output_buffer);
    frfree(p_inbuffer);
}

static void __case7(void)
{
    FILE *fp_stdin = NULL;
    FILE *fp_stdout = NULL;
    char *p_out = NULL;//实际应该输出的字符串
    int i_out_len = 0;
    char *p_inbuffer = NULL;
    unsigned int ui_inbuffer_size = 0;
    char *p_from_charset = (char *)"big5";
    char *p_output_buffer = NULL;
    unsigned int p_ui_output_size = 0;

    fp_stdin = fopen("t_iconv2utf8/input5.txt","r");
    if(fp_stdin == NULL)
        return;

    fseek(fp_stdin,0,SEEK_SET);
    fseek(fp_stdin,0,SEEK_END);
    ui_inbuffer_size = ftell(fp_stdin);
    rewind(fp_stdin);

    p_inbuffer = (char *)frmalloc(ui_inbuffer_size + 1);
    if(p_inbuffer == NULL)
    {
        fclose(fp_stdin);
        return;
    }

    if(fread(p_inbuffer, 1, (int)ui_inbuffer_size,fp_stdin) != ui_inbuffer_size)
    {
        fclose(fp_stdin);
        frfree(p_inbuffer);
        return;
    }


    iconv_to_utf8(p_inbuffer, ui_inbuffer_size, p_from_charset, &p_output_buffer, &p_ui_output_size);

    fp_stdout = fopen("t_iconv2utf8/big5.txt","r");
    if(fp_stdout == NULL)
    {
        frfree(p_inbuffer);
        fclose(fp_stdin);
        frfree(p_output_buffer);
        return;
    }


    fseek(fp_stdout,0,SEEK_SET);
    fseek(fp_stdout,0,SEEK_END);
    i_out_len = ftell(fp_stdout);
    rewind(fp_stdout);

    p_out =(char *)frmalloc(i_out_len + 1);
    memset(p_out,'\0',i_out_len + 1);
    if(p_out == NULL)
    {
        frfree(p_inbuffer);
        fclose(fp_stdin);
        frfree(p_output_buffer);
        fclose(fp_stdout);
        return;
    }

    if(fread(p_out,1,i_out_len,fp_stdout) != (unsigned int)i_out_len)
    {
        frfree(p_inbuffer);
        fclose(fp_stdin);
        frfree(p_output_buffer);
        fclose(fp_stdout);
        frfree(p_out);
        return;
    }
    fclose(fp_stdout);


    CU_ASSERT_STRING_EQUAL(p_out,p_output_buffer);
    frfree(p_out);
    frfree(p_output_buffer);
}

static void __case8(void)
{
    FILE *fp_stdin = NULL;
    FILE *fp_stdout = NULL;
    char *p_out = NULL;//实际应该输出的字符串
    int i_out_len = 0;
    char *p_inbuffer = NULL;
    unsigned int ui_inbuffer_size = 0;
    char *p_from_charset = (char *)"ASMO-708";
    char *p_output_buffer = NULL;
    unsigned int p_ui_output_size = 0;

    fp_stdin = fopen("t_iconv2utf8/input6.txt","r");
    if(fp_stdin == NULL)
        return;

    fseek(fp_stdin,0,SEEK_SET);
    fseek(fp_stdin,0,SEEK_END);
    ui_inbuffer_size = ftell(fp_stdin);
    rewind(fp_stdin);

    p_inbuffer = (char *)frmalloc(ui_inbuffer_size + 1);
    if(p_inbuffer == NULL)
    {
        fclose(fp_stdin);
        return;
    }

    if(fread(p_inbuffer, 1, (int)ui_inbuffer_size,fp_stdin) != ui_inbuffer_size)
    {
        fclose(fp_stdin);
        frfree(p_inbuffer);
        return;
    }


    if(iconv_to_utf8(p_inbuffer, ui_inbuffer_size, p_from_charset, &p_output_buffer, &p_ui_output_size))
    {
        if(p_output_buffer)
            frfree(p_output_buffer);
        frfree(p_inbuffer);
        fclose(fp_stdin);
        printf("iconv error");
        return;
    }

    fp_stdout = fopen("t_iconv2utf8/ASMO-708.txt","r");
    if(fp_stdout == NULL)
    {
        frfree(p_inbuffer);
        fclose(fp_stdin);
        frfree(p_output_buffer);
        return;
    }


    fseek(fp_stdout,0,SEEK_SET);
    fseek(fp_stdout,0,SEEK_END);
    i_out_len = ftell(fp_stdout);
    rewind(fp_stdout);

    p_out =(char *)frmalloc(i_out_len + 1);
    memset(p_out,'\0',i_out_len + 1);
    if(p_out == NULL)
    {
        frfree(p_inbuffer);
        fclose(fp_stdin);
        frfree(p_output_buffer);
        fclose(fp_stdout);
        return;
    }

    if(fread(p_out,1,i_out_len,fp_stdout) != (unsigned int)i_out_len)
    {
        frfree(p_inbuffer);
        fclose(fp_stdin);
        frfree(p_output_buffer);
        fclose(fp_stdout);
        frfree(p_out);
        return;
    }
    fclose(fp_stdout);

    CU_ASSERT_STRING_EQUAL(p_out,p_output_buffer);
    frfree(p_out);
    frfree(p_output_buffer);
}

static void __case9(void)
{
    FILE *fp_stdin = NULL;
    FILE *fp_stdout = NULL;
    char *p_out = NULL;//实际应该输出的字符串
    int i_out_len = 0;
    char *p_inbuffer = NULL;
    unsigned int ui_inbuffer_size = 0;
    char *p_from_charset = (char *)"IBM037";
    char *p_output_buffer = NULL;
    unsigned int p_ui_output_size = 0;

    fp_stdin = fopen("t_iconv2utf8/input7.txt","r");
    if(fp_stdin == NULL)
        return;

    fseek(fp_stdin,0,SEEK_SET);
    fseek(fp_stdin,0,SEEK_END);
    ui_inbuffer_size = ftell(fp_stdin);
    rewind(fp_stdin);

    p_inbuffer = (char *)frmalloc(ui_inbuffer_size + 1);
    if(p_inbuffer == NULL)
    {
        fclose(fp_stdin);
        return;
    }

    if(fread(p_inbuffer, 1, (int)ui_inbuffer_size,fp_stdin) != ui_inbuffer_size)
    {
        fclose(fp_stdin);
        frfree(p_inbuffer);
        return;
    }


    iconv_to_utf8(p_inbuffer, ui_inbuffer_size, p_from_charset, &p_output_buffer, &p_ui_output_size);
    fp_stdout = fopen("t_iconv2utf8/IBM037.txt","w");
    fprintf(fp_stdout,"%s",p_output_buffer);
    fclose(fp_stdout);
    fp_stdout = fopen("t_iconv2utf8/IBM037.txt","r");
    if(fp_stdout == NULL)
    {
        frfree(p_inbuffer);
        fclose(fp_stdin);
        frfree(p_output_buffer);
        return;
    }


    fseek(fp_stdout,0,SEEK_SET);
    fseek(fp_stdout,0,SEEK_END);
    i_out_len = ftell(fp_stdout);
    rewind(fp_stdout);

    p_out =(char *)frmalloc(i_out_len + 1);
    memset(p_out,'\0',i_out_len + 1);
    if(p_out == NULL)
    {
        frfree(p_inbuffer);
        fclose(fp_stdin);
        frfree(p_output_buffer);
        fclose(fp_stdout);
        return;
    }

    if(fread(p_out,1,i_out_len,fp_stdout) != (unsigned int)i_out_len)
    {
        frfree(p_inbuffer);
        fclose(fp_stdin);
        frfree(p_output_buffer);
        fclose(fp_stdout);
        frfree(p_out);
        return;
    }
    fclose(fp_stdout);


    CU_ASSERT_STRING_EQUAL(p_out,p_output_buffer);
    frfree(p_inbuffer);
    frfree(p_out);
    frfree(p_output_buffer);
}

static void __case10(void)
{
    FILE *fp_stdin = NULL;
    FILE *fp_stdout = NULL;
    char *p_out = NULL;//实际应该输出的字符串
    int i_out_len = 0;
    char *p_inbuffer = NULL;
    unsigned int ui_inbuffer_size = 0;
    char *p_from_charset = (char *)"cp875";
    char *p_output_buffer = NULL;
    unsigned int p_ui_output_size = 0;

    fp_stdin = fopen("t_iconv2utf8/input8.txt","r");
    if(fp_stdin == NULL)
        return;

    fseek(fp_stdin,0,SEEK_SET);
    fseek(fp_stdin,0,SEEK_END);
    ui_inbuffer_size = ftell(fp_stdin);
    rewind(fp_stdin);

    p_inbuffer = (char *)frmalloc(ui_inbuffer_size + 1);
    if(p_inbuffer == NULL)
    {
        fclose(fp_stdin);
        return;
    }

    if(fread(p_inbuffer, 1, (int)ui_inbuffer_size,fp_stdin) != ui_inbuffer_size)
    {
        fclose(fp_stdin);
        frfree(p_inbuffer);
        return;
    }


    if(iconv_to_utf8(p_inbuffer, ui_inbuffer_size, p_from_charset, &p_output_buffer, &p_ui_output_size))
    {
        frfree(p_inbuffer);
        fclose(fp_stdin);
        frfree(p_output_buffer);
        return;
    }


    fp_stdout = fopen("t_iconv2utf8/cp875.txt","r");

    if(fp_stdout == NULL)
    {
        frfree(p_inbuffer);
        fclose(fp_stdin);
        frfree(p_output_buffer);
        return;
    }


    fseek(fp_stdout,0,SEEK_SET);
    fseek(fp_stdout,0,SEEK_END);
    i_out_len = ftell(fp_stdout);
    rewind(fp_stdout);

    p_out =(char *)frmalloc(i_out_len + 1);
    memset(p_out,'\0',i_out_len + 1);
    if(p_out == NULL)
    {
        frfree(p_inbuffer);
        fclose(fp_stdin);
        frfree(p_output_buffer);
        fclose(fp_stdout);
        return;
    }

    if(fread(p_out,1,i_out_len,fp_stdout) != (unsigned int)i_out_len)
    {
        frfree(p_inbuffer);
        fclose(fp_stdin);
        frfree(p_output_buffer);
        fclose(fp_stdout);
        frfree(p_out);
        return;
    }
    fclose(fp_stdout);

//    CU_ASSERT_STRING_EQUAL(p_out,p_output_buffer);
    printf("%s\n", p_output_buffer);

    frfree(p_inbuffer);
    frfree(p_out);
    frfree(p_output_buffer);
}

static void __case11(void)
{
    FILE *fp_stdin = NULL;
    char *p_inbuffer = NULL;
    unsigned int ui_inbuffer_size = 0;
    char *p_from_charset = (char *)"DOS-720";
    char *p_output_buffer = NULL;
    unsigned int p_ui_output_size = 0;

    fp_stdin = fopen("t_iconv2utf8/input9.txt","r");
    if(fp_stdin == NULL)
        return;

    fseek(fp_stdin,0,SEEK_SET);
    fseek(fp_stdin,0,SEEK_END);
    ui_inbuffer_size = ftell(fp_stdin);
    rewind(fp_stdin);

    p_inbuffer = (char *)frmalloc(ui_inbuffer_size + 1);
    if(p_inbuffer == NULL)
    {
        fclose(fp_stdin);
        return;
    }

    if(fread(p_inbuffer, 1, (int)ui_inbuffer_size,fp_stdin) != ui_inbuffer_size)
    {
        fclose(fp_stdin);
        frfree(p_inbuffer);
        return;
    }


    if(iconv_to_utf8(p_inbuffer, ui_inbuffer_size, p_from_charset, &p_output_buffer, &p_ui_output_size))
    {
        frfree(p_inbuffer);
        fclose(fp_stdin);
        printf("iconv error");
    }



    CU_ASSERT_PTR_NULL(p_output_buffer);
    frfree(p_output_buffer);
}



static void __case12(void)
{
    FILE *fp_stdin = NULL;
    char *p_inbuffer = NULL;
    unsigned int ui_inbuffer_size = 0;
    char *p_from_charset = (char *)"aaa";
    char *p_output_buffer = NULL;
    unsigned int p_ui_output_size = 0;

    fp_stdin = fopen("t_iconv2utf8/input1.txt","r");
    if(fp_stdin == NULL)
        return;

    fseek(fp_stdin,0,SEEK_SET);
    fseek(fp_stdin,0,SEEK_END);
    ui_inbuffer_size = ftell(fp_stdin);
    rewind(fp_stdin);

    p_inbuffer = (char *)frmalloc(ui_inbuffer_size + 1);
    if(p_inbuffer == NULL)
    {
        fclose(fp_stdin);
        return;
    }

    if(fread(p_inbuffer, 1, (int)ui_inbuffer_size,fp_stdin) != ui_inbuffer_size)
    {
        fclose(fp_stdin);
        frfree(p_inbuffer);
        return;
    }


    if(iconv_to_utf8(p_inbuffer, ui_inbuffer_size, p_from_charset, &p_output_buffer, &p_ui_output_size))
    {
        frfree(p_inbuffer);
        fclose(fp_stdin);
        printf("iconv error");
    }

    CU_ASSERT_PTR_NULL(p_output_buffer);
}

static void __case13(void)
{
    FILE *fp_stdin = NULL;
    FILE *fp_stdout = NULL;
    char *p_out = NULL;//实际应该输出的字符串
    int i_out_len = 0;
    char *p_inbuffer = NULL;
    unsigned int ui_inbuffer_size = 0;
    char *p_from_charset = (char *)"GB2312";
    char *p_output_buffer = NULL;
    unsigned int p_ui_output_size = 0;

    fp_stdin = fopen("t_iconv2utf8/input11.txt","r");
    if(fp_stdin == NULL)
        return;

    fseek(fp_stdin,0,SEEK_SET);
    fseek(fp_stdin,0,SEEK_END);
    ui_inbuffer_size = ftell(fp_stdin);
    rewind(fp_stdin);

    p_inbuffer = (char *)frmalloc(ui_inbuffer_size + 1);
    if(p_inbuffer == NULL)
    {
        fclose(fp_stdin);
        return;
    }

    if(fread(p_inbuffer, 1, (int)ui_inbuffer_size,fp_stdin) != ui_inbuffer_size)
    {
        fclose(fp_stdin);
        frfree(p_inbuffer);
        return;
    }


    if(iconv_to_utf8(p_inbuffer, ui_inbuffer_size, p_from_charset, &p_output_buffer, &p_ui_output_size))
    {
        fp_stdout = fopen("t_iconv2utf8/case14.txt","w");
        fprintf(fp_stdout,"%s",p_output_buffer);
        fclose(fp_stdout);
        frfree(p_inbuffer);
        fclose(fp_stdin);
        printf("iconv error");

    }
    fp_stdout = fopen("t_iconv2utf8/case14.txt","r");
    if(fp_stdout == NULL)
    {
        frfree(p_inbuffer);
        fclose(fp_stdin);
        frfree(p_output_buffer);
        return;
    }


    fseek(fp_stdout,0,SEEK_SET);
    fseek(fp_stdout,0,SEEK_END);
    i_out_len = ftell(fp_stdout);
    rewind(fp_stdout);

    p_out =(char *)frmalloc(i_out_len + 1);
    memset(p_out,'\0',i_out_len + 1);
    if(p_out == NULL)
    {
        frfree(p_inbuffer);
        fclose(fp_stdin);
        frfree(p_output_buffer);
        fclose(fp_stdout);
        return;
    }

    if(fread(p_out,1,i_out_len,fp_stdout) != (unsigned int)i_out_len)
    {
        frfree(p_inbuffer);
        fclose(fp_stdin);
        frfree(p_output_buffer);
        fclose(fp_stdout);
        frfree(p_out);
        return;
    }
    fclose(fp_stdout);


    CU_ASSERT_STRING_EQUAL(p_out,p_output_buffer);
    frfree(p_out);
    frfree(p_output_buffer);
}



int add_suite_iconv2utf8(void)
{
    CU_pSuite pSuite = NULL;

    if ((pSuite = CU_add_suite("iconv2utf8 iconv2utf8()", __suite_init, __suite_cleanup)) == NULL)
        return FR_FAIL;

    CU_add_test(pSuite, "case1", __case1);
    CU_add_test(pSuite, "case2", __case2);
    CU_add_test(pSuite, "case3", __case3);
    CU_add_test(pSuite, "case4", __case4);
    CU_add_test(pSuite, "case5", __case5);
    CU_add_test(pSuite, "case6", __case6);
    CU_add_test(pSuite, "case7", __case7);
    CU_add_test(pSuite, "case8", __case8);
    CU_add_test(pSuite, "case9", __case9);
    CU_add_test(pSuite, "case10", __case10);
    CU_add_test(pSuite, "case11", __case11);
    CU_add_test(pSuite, "case12", __case12);
    CU_add_test(pSuite, "case13", __case13);

    return FR_SUCC;
}
